//
//  LXPermissionFaceId.swift
//  LXPermissionAuth
//
//  Created by yoctech on 2021/8/18.
//

import UIKit
import LocalAuthentication

@objc class LXPermissionFaceId: NSObject, LXPermissionProtocol {
    @objc public static func auth(autoRequestIfNot: Bool, clouser: @escaping LXAuthClouser) {
        let context = LAContext()
        var error: NSError?
        let result = context.canEvaluatePolicy(.deviceOwnerAuthentication, error: &error)
        if result {
            context.evaluatePolicy(.deviceOwnerAuthentication, localizedReason: "认证") { (success, authError) in
                if success{
                    clouser(true, .authorized)
                }else{
                    clouser(false, .other)
                }
            }
        }else{
            /**
             #define kLAErrorAuthenticationFailed                       -1
             #define kLAErrorUserCancel                                 -2
             #define kLAErrorUserFallback                               -3
             #define kLAErrorSystemCancel                               -4
             #define kLAErrorPasscodeNotSet                             -5
             #define kLAErrorTouchIDNotAvailable                        -6
             #define kLAErrorTouchIDNotEnrolled                         -7
             #define kLAErrorTouchIDLockout                             -8
             #define kLAErrorAppCancel                                  -9
             #define kLAErrorInvalidContext                            -10
             #define kLAErrorNotInteractive                          -1004
             
             #define kLAErrorBiometryNotAvailable              kLAErrorTouchIDNotAvailable
             #define kLAErrorBiometryNotEnrolled               kLAErrorTouchIDNotEnrolled
             
             */
            clouser(false, .restricted)
        }

    }
    

}
